import request from '@/utils/request'
import { reviseParam } from '@/utils/util'

const mgr = './mgr'
const url = {
  ORG_LIST: `${mgr}/WeBASE-Node-Manager`
}

export function getblockList(data, list) {
  const params = reviseParam(data, list)
  return request({
    baseURL: process.env.VUE_APP_IS_PROXY === '1' ? '' : process.env.VUE_APP_MGR_URL,
    url: `${url.ORG_LIST}/block/blockList/${params.str}`,
    method: 'get',
    params: params.querys,
    headers: {
      AuthorizationToken: 'Token ' + localStorage.getItem('token') || ''
    }
  })
}

export function getTransactionList(data, list) {
  const params = reviseParam(data, list)
  return request({
    baseURL: process.env.VUE_APP_IS_PROXY === '1' ? '' : process.env.VUE_APP_MGR_URL,
    url: `${url.ORG_LIST}/transaction/transList/${params.str}`,
    method: 'get',
    params: params.querys,
    headers: {
      AuthorizationToken: 'Token ' + localStorage.getItem('token') || ''
    }
  })
}

export function getContractList(data) {
  return request({
    baseURL: process.env.VUE_APP_IS_PROXY === '1' ? '' : process.env.VUE_APP_MGR_URL,
    url: `${url.ORG_LIST}/contract/contractList`,
    method: 'post',
    data: data,
    headers: {
      AuthorizationToken: 'Token ' + localStorage.getItem('token') || ''
    }
  })
}

export function getByteCode(data, list) {
  const params = reviseParam(data, list)
  return request({
    baseURL: process.env.VUE_APP_IS_PROXY === '1' ? '' : process.env.VUE_APP_MGR_URL,
    url: `${url.ORG_LIST}/web3/code/${params.str}`,
    method: 'get',
    params: params.querys,
    headers: {
      AuthorizationToken: 'Token ' + localStorage.getItem('token') || ''
    }
  })
}

export function getTransactionReceipt(data, list) {
  const params = reviseParam(data, list)
  return request({
    baseURL: process.env.VUE_APP_IS_PROXY === '1' ? '' : process.env.VUE_APP_MGR_URL,
    url: `${url.ORG_LIST}/transaction/transactionReceipt/${params.str}`,
    method: 'get',
    params: params.querys,
    headers: {
      AuthorizationToken: 'Token ' + localStorage.getItem('token') || ''
    }
  })
}

export function hashTransactionInfo(data, list) {
  const params = reviseParam(data, list)
  return request({
    baseURL: process.env.VUE_APP_IS_PROXY === '1' ? '' : process.env.VUE_APP_MGR_URL,
    url: `${url.ORG_LIST}/transaction/transInfo/${params.str}`,
    method: 'get',
    params: params.querys,
    headers: {
      AuthorizationToken: 'Token ' + localStorage.getItem('token') || ''
    }
  })
}

export function getBlockDetail(data, list) {
  const params = reviseParam(data, list)
  return request({
    baseURL: process.env.VUE_APP_IS_PROXY === '1' ? '' : process.env.VUE_APP_MGR_URL,
    url: `${url.ORG_LIST}/block/blockByNumber/${params.str}`,
    method: 'get',
    params: params.querys,
    headers: {
      AuthorizationToken: 'Token ' + localStorage.getItem('token') || ''
    }
  })
}

export function getNetworkStatistics(data) {
  return request({
    baseURL: process.env.VUE_APP_IS_PROXY === '1' ? '' : process.env.VUE_APP_MGR_URL,
    url: `${url.ORG_LIST}/group/general/${data}`,
    method: 'get',
    headers: {
      AuthorizationToken: 'Token ' + localStorage.getItem('token') || ''
    }
  })
}

export function getChartData(data) {
  return request({
    baseURL: process.env.VUE_APP_IS_PROXY === '1' ? '' : process.env.VUE_APP_MGR_URL,
    url: `${url.ORG_LIST}/group/transDaily/${data}`,
    method: 'get',
    headers: {
      AuthorizationToken: 'Token ' + localStorage.getItem('token') || ''
    }
  })
}

/**
 * 检测是否有概览权限
 * @param {*} params
 * @returns
 */
export function checkCanShowOverview(params) {
  return request({
    url: '/account/overview',
    method: 'get',
    params
  })
}
